//
//  AllotOrderDisposeViewController.m
//  TryShopping
//
//  Created by panquanReabam.com on 16/9/18.
//  Copyright © 2016年 RuiBen. All rights reserved.
//

#import "AllotOrderDisposeViewController.h"

#import "webCollectionViewCell.h"
#import "ZJSwitch.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "UIImageView+WebCache.h"
#import "RDVTabBarController.h"
#import "TimeView.h"

@interface AllotOrderDisposeViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UITextViewDelegate,UISearchBarDelegate,UIScrollViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,UIActionSheetDelegate, UICollectionViewDelegateFlowLayout,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIGestureRecognizerDelegate>

@end

@implementation AllotOrderDisposeViewController
{
    TimeView*timeView;
    UIView*view;
    UITextView* tv;
    UILabel * label;
    UIImageView*images;
    UIView* myToolBar;
    UIScrollView*MYmainScroll;
    NSMutableArray *imageArray;
    UIView*imageView;
    NSMutableArray*imageList;
    NSUInteger ArrayCount;
}

-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
    self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    self.title = self.titleName;
    self.view.backgroundColor=[UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     backColor,
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
}
- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    MYmainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];
    [MYmainScroll setBackgroundColor: zuiqianhuiColor];
    MYmainScroll.delegate = self;
    MYmainScroll.userInteractionEnabled = YES;
    MYmainScroll.scrollEnabled = YES;
    MYmainScroll.showsVerticalScrollIndicator = FALSE;
    MYmainScroll.showsHorizontalScrollIndicator = FALSE;
    [self.view addSubview:MYmainScroll];
    
    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone .titleLabel .font=[UIFont systemFontOfSize:keyboardFot];
    [btnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    [self update:@""];
    
   
    UIButton* registed = [[UIButton alloc] initWithFrame:CGRectMake(0,ScreenHeight-48 ,ScreenWidth, 48)];
    if ([self.titleName isEqualToString:@"调拨确认"]) {
         [registed setTitle:@"受理确认" forState:UIControlStateNormal];
    }else{
     [registed setTitle:self.titleName forState:UIControlStateNormal];
    
    }
   
    registed.backgroundColor=luseColor;
    [registed setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    registed.titleLabel.font=[UIFont systemFontOfSize:16];
    if ([_Type isEqualToString:@"Order"]) {
         [registed addTarget:self action:@selector(orderGO:) forControlEvents:UIControlEventTouchUpInside];
    }else{
        [registed addTarget:self action:@selector(GO:) forControlEvents:UIControlEventTouchUpInside];}
    [self.view addSubview:registed];
    
    
    
    
}

- (void)update:(NSString *)str{
    view=[[UIView alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 120)];
    view.backgroundColor=[UIColor whiteColor];
    view.layer.borderWidth = 0.40;
    view.layer.borderColor = qianhuiColor.CGColor;
    [MYmainScroll addSubview:view];
    tv=[[UITextView alloc]init];
    tv.frame=CGRectMake(20, 10, ScreenWidth-40, 90);
    tv.backgroundColor = [UIColor whiteColor];//设置它的背景颜色/Users/jiezsoft/Desktop/
    tv.scrollEnabled = YES;//是否可以拖动
    tv.delegate=self;
    tv.font = [UIFont fontWithName:@"Arial" size:15.0];//设置字体名字和字体大小
    tv.layer.borderWidth =0.0;
    CGColorSpaceRef registedSpace11 = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref111 = CGColorCreate(registedSpace11,(CGFloat[]){ 0, 0, 0, 0.3 });
    [tv.layer setBorderColor:tureBTncolorref111];//边框颜色
    tv.layer.cornerRadius =0;
    [view addSubview:tv];
    images=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 20, 16)];
    images.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
    [tv addSubview:images];
    label=[[UILabel alloc]init];
    label.frame =CGRectMake(23, 7, ScreenWidth-60, 14);
    label.text = @"备注";
    label.textColor=qianhuiColor;
    label.numberOfLines=0;
    label.font=[UIFont systemFontOfSize:14];
    [tv addSubview:label];
    tv.inputAccessoryView = myToolBar;
    
    
    
}

-(void)orderGO:(UIButton*)sender{
    if ([_titleName isEqualToString:@"取消订单"]) {
        
                    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                    NSString* Token = [user objectForKey:@"tokenId"];
                    NSMutableDictionary *params = [NSMutableDictionary new];
                    [params setValue:Token forKey:@"tokenId"];
                    [params setValue:tv.text forKey:@"remark"];
                    [params setValue:self.orderId forKey:@"orderId"];
                    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
                    [HttpRequest requestData:@"Business/Order/Cancel" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                        if (isSuccess) {
                            NSLog(@"-----------%@", severDataDict.dataDict);
                            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                                [Global hideProgressHUDInternal:self.view];
                                [_mDelegate update:@""];
                                [self.navigationController popViewControllerAnimated:YES];

        
                              
                            }else{
                                [Global hideProgressHUDInternal:self.view];
                                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                                [Global showTextHudSub:requestResultStr view:self.view];
                            }}
                        else
                        {
                            [Global hideProgressHUDInternal:self.view];
                            [Global showTextHudSub:severDataDict.resultStr view:self.view];
                        }
                        
                    }];
    }else{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:Token forKey:@"tokenId"];
    [params setValue:self.optType forKey:@"optType"];
    
    [params setValue:tv.text forKey:@"remark"];
    [params setValue:self.orderId forKey:@"orderId"];
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    NSLog(@"params-----------%@", params);
    [HttpRequest requestData:@"Business/Order/Accept" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            NSLog(@"-----------%@", severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                [_mDelegate update:@""];
                [self.navigationController popViewControllerAnimated:YES];
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }}
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
        
    }];
    
    
    }
}

-(void)GO:(UIButton*)sender{
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:Token forKey:@"tokenId"];
    [params setValue:self.optType forKey:@"optType"];
    
    [params setValue:tv.text forKey:@"remark"];
    [params setValue:self.orderId forKey:@"orderId"];
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    NSLog(@"params-----------%@", params);
    [HttpRequest requestData:@"Allot/Order/Dispose" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            NSLog(@"-----------%@", severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                [_mDelegate update:@""];
                [self.navigationController popViewControllerAnimated:YES];
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }}
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
        
    }];
    
    
    
}
-(void)textViewDidChange:(UITextView *)textView
{
    
    if (textView.text.length == 0) {
        [images removeFromSuperview];
        images=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 20, 16)];
        images.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [tv addSubview:images];
        label.text = @"备注";
        
    }else{
        [images removeFromSuperview];
        label.text = @"";
    }
}
//回收键盘
-(void)OnTapDone{
    [tv resignFirstResponder];
   
    
}

@end
